﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.storage {
    import flash.utils.*;
    import Classes.*;
    import __AS3__.vec.*;

    public class StorageComponent {

        private var m_storage:Dictionary;

        public function StorageComponent(){
            this.m_storage = new Dictionary();
        }
        public function loadObject(_arg1:Object):void{
            var _local2:Object;
            var _local3:String;
            var _local4:StorageType;
            var _local5:Object;
            var _local6:String;
            var _local7:Object;
            var _local8:BaseStorageUnit;
            if (_arg1){
                _local2 = _arg1["m_storage"];
                for (_local3 in _local2) {
                    _local4 = StorageType.createEnum(_local3);
                    this.m_storage[_local4] = new Dictionary();
                    _local5 = _local2[_local3];
                    for (_local6 in _local5) {
                        _local7 = _local5[_local6];
                        _local8 = new BaseStorageUnit();
                        _local8.loadObject(_local7);
                        this.m_storage[_local4][_local6] = _local8;
                    };
                };
            };
        }
        public function get size():int{
            var _local3:BaseStorageUnit;
            var _local1:int;
            var _local2:Vector.<BaseStorageUnit> = this.getAllStorageUnits();
            for each (_local3 in _local2) {
                _local1 = (_local1 + _local3.size);
            };
            return (_local1);
        }
        public function validate(_arg1:ItemInstance, _arg2:StorageType, _arg3:String):Boolean{
            var _local4:Boolean = _arg1.getItem().storable;
            var _local5:Function = StorageType.getValidateFunction(_arg2);
            return (((_local4) && (_local5(_arg1, _arg3))));
        }
        public function getValidStorageUnits(_arg1:ItemInstance):Vector.<StorageId>{
            var _local4:StorageType;
            var _local5:Vector.<String>;
            var _local6:String;
            var _local2:Vector.<StorageId> = new Vector.<StorageId>();
            var _local3:Vector.<StorageType> = this.getStorageTypes();
            for each (_local4 in _local3) {
                _local5 = this.getKeysByType(_local4);
                for each (_local6 in _local5) {
                    if (this.validate(_arg1, _local4, _local6)){
                        _local2.push(new StorageId(_local4, _local6));
                    };
                };
            };
            return (_local2);
        }
        public function addStorageUnit(_arg1:StorageType, _arg2:String):BaseStorageUnit{
            var _local3:BaseStorageUnit;
            if (this.m_storage[_arg1] == null){
                this.m_storage[_arg1] = new Dictionary();
            };
            var _local4:Dictionary = (this.m_storage[_arg1] as Dictionary);
            if (_local4[_arg2] == null){
                _local3 = new BaseStorageUnit();
                _local4[_arg2] = _local3;
            } else {
                _local3 = _local4[_arg2];
            };
            return (_local3);
        }
        public function removeStorageUnit(_arg1:StorageType, _arg2:String):void{
            var _local4:int;
            var _local3:Dictionary = this.m_storage[_arg1];
            if (_local3 != null){
                delete _local3[_arg2];
                _local4 = 0;
                for (_arg2 in _local3) {
                    _local4++;
                };
                if (_local4 == 0){
                    delete this.m_storage[_arg1];
                };
            };
        }
        public function getItemsByName(_arg1:String):Vector.<ItemInstance>{
            var _local4:BaseStorageUnit;
            var _local5:Vector.<ItemInstance>;
            var _local2:Vector.<ItemInstance> = new Vector.<ItemInstance>();
            var _local3:Vector.<BaseStorageUnit> = this.getAllStorageUnits();
            for each (_local4 in _local3) {
                if (_local4 != null){
                    _local5 = _local4.getItemsByName(_arg1);
                    if (_local5 != null){
                        _local2 = _local2.concat(_local5);
                    };
                };
            };
            return (_local2);
        }
        public function getItemsByType(_arg1:String):Vector.<ItemInstance>{
            var _local4:BaseStorageUnit;
            var _local2:Vector.<BaseStorageUnit> = this.getAllStorageUnits();
            var _local3:Vector.<ItemInstance> = new Vector.<ItemInstance>();
            for each (_local4 in _local2) {
                if (_local4 != null){
                    _local3 = _local3.concat(_local4.getItemsByType(_arg1));
                };
            };
            return (_local3);
        }
        public function getStorageUnit(_arg1:StorageType, _arg2:String):BaseStorageUnit{
            var _local3:BaseStorageUnit;
            var _local4:Dictionary = this.m_storage[_arg1];
            if (_local4 != null){
                _local3 = (_local4[_arg2] as BaseStorageUnit);
            };
            return (_local3);
        }
        public function getStorageTypes():Vector.<StorageType>{
            var _local2:Object;
            var _local3:StorageType;
            var _local1:Vector.<StorageType> = new Vector.<StorageType>();
            for (_local2 in this.m_storage) {
                _local3 = (_local2 as StorageType);
                _local1.push(_local3);
            };
            return (_local1);
        }
        public function getAllStorageUnits():Vector.<BaseStorageUnit>{
            var _local3:StorageType;
            var _local1:Vector.<BaseStorageUnit> = new Vector.<BaseStorageUnit>();
            var _local2:Vector.<StorageType> = this.getStorageTypes();
            for each (_local3 in _local2) {
                _local1 = _local1.concat(this.getStorageUnitsByType(_local3));
            };
            return (_local1);
        }
        public function getStorageUnitsByType(_arg1:StorageType):Vector.<BaseStorageUnit>{
            var _local4:BaseStorageUnit;
            var _local2:Vector.<BaseStorageUnit> = new Vector.<BaseStorageUnit>();
            var _local3:Dictionary = this.getStorageTypeComponent(_arg1);
            for each (_local4 in _local3) {
                _local2.push(_local4);
            };
            return (_local2);
        }
        public function getKeysByType(_arg1:StorageType):Vector.<String>{
            var _local4:String;
            var _local2:Vector.<String> = new Vector.<String>();
            var _local3:Dictionary = this.m_storage[_arg1];
            for (_local4 in _local3) {
                _local2.push(_local4);
            };
            return (_local2);
        }
        private function getStorageTypeComponent(_arg1:StorageType):Dictionary{
            return ((this.m_storage[_arg1] as Dictionary));
        }

    }
}//package Modules.storage 
